const mongoose = require('mongoose');
const {dburl} = require('../config/config.default');

//连接数据库
mongoose.connect(dburl,{
    useNewUrlParser: true,
    useUnifiedTopology: true
});

const db = mongoose.connection;

//连接失败
db.on('error', err => {
    console.log('connection error:', err)
});
//连接成功
db.once('open', function () {
    console.log('db ok')
});


const Cat = mongoose.model('Cat', {name: String});

const kitty = new Cat({name: 'Zildjian'});
kitty.save().then(() => console.log('meow'));